<template>
  <div style="height: 100px">
    <!--卡片-->
    <el-card class="box-card">
      <!--定义面包屑-->
      <el-breadcrumb separator=">">
            <el-breadcrumb-item :to="{ path: '/main' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>客户管理</el-breadcrumb-item>
            <el-breadcrumb-item>积分记录</el-breadcrumb-item>
          </el-breadcrumb>
      <el-divider></el-divider>
      <div style="">
        <!-- 表单的搜索框 :model="双向绑定表单的数据" -->
        <el-form :inline="true" :model="pointsSelect"  class="demo-form-inline">
              <el-form-item >
                <el-input v-model="pointsSelect.id" placeholder="请输入ID"></el-input>
              </el-form-item>
              <el-form-item >
                <div class="block">
                  <el-date-picker
                      v-model="pointsSelect.createTime"
                      align="right"
                      type="date"
                      value-format="yyyy-MM-dd"
                      placeholder="选择日期"
                      :picker-options="pickerOptions">
                  </el-date-picker>
                </div>
              </el-form-item>
              <el-form-item >
                <el-input v-model="pointsSelect.username" placeholder="请输入账号"></el-input>
              </el-form-item>
              <el-form-item >
                <el-select v-model="pointsSelect.changeType" placeholder="积分变化类型">
                  <el-option
                      v-for="item in optionChangeType"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item >
                <el-input v-model="pointsSelect.operateMan" placeholder="操作人员"></el-input>
              </el-form-item>
              <el-form-item >
                <el-select v-model="pointsSelect.sourceType" placeholder="积分来源">
                  <el-option
                      v-for="item in optionSourceType"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>

              <el-form-item>
                <el-button type="primary" @click="initpointsTable">查询</el-button>
              </el-form-item>
            </el-form>
        <!--数据表格-->
        <template>
          <el-table
              :data="tableData"
              :border="true"
              stripe
              style="width:100%">
            <!--            height="666"-->
            <el-table-column
              prop="id"
              label="积分记录id"
              fixed="left"
              sortable
            >
            </el-table-column>
            <el-table-column
               prop="memberId"
               label="会员ID"
               fixed="left"
               sortable
            >
            </el-table-column>
            <el-table-column
                prop="username"
                label="会员账号"
                fixed="left"
                sortable
            >
            </el-table-column>
            <el-table-column
                prop="createTime"
                label="创建记录时间"
                sortable
            >
            </el-table-column>
            <el-table-column
              prop="changeType"
              label="积分变化类型"
              sortable>
              <template slot-scope="scope">
                <span v-if="scope.row.changeType===0">加</span>
                <span v-if="scope.row.changeType===1">减</span>
              </template>
            </el-table-column>
            <el-table-column
               prop="changeCount"
               label="积分改变数量"
               sortable>
            </el-table-column>
            <el-table-column
               prop="operateMan"
               label="操作人员"
               sortable>
            </el-table-column>
            <el-table-column
               prop="operateNote"
               label="操作备注"
               sortable>
            </el-table-column>
            <el-table-column
               prop="sourceType"
               label="积分来源"
               sortable>
              <template slot-scope="scope">
                <span v-if="scope.row.sourceType===0">自驾服务消费金额</span>
                <span v-if="scope.row.sourceType===1">参与官方活动</span>
                <span v-if="scope.row.sourceType===2">官网或.app专车或者个人消费后</span>
              </template>
            </el-table-column>
          </el-table>
          <!--分页-->
          <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="[5, 10, 15, 20]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
                </el-pagination>
        </template>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "Points",
  data(){
    return {
      //条件搜索对象
      pointsSelect:{},
      //表格数据
      tableData:[],
      //每页显示的条数
      pageSize: 5,
      //当前的显示的页码
      currentPage:1,
      //总条数
      total:0,
      //分配角色框的显示
      fenRoleDialog:false,
      //表单元素
      ruleForm:{},
      //表单校验规则
      rules: {
        name: [
          { required: true, message: '请输入会员名称', trigger: 'blur' },
        ],
      },
      titleName:"",
      optionChangeType:[{
        value: 1,
        label: '加'
      }, {
        value: 2,
        label: '减'
      }],
      optionSourceType:[{
        value: 0,
        label: '自驾服务消费金额'
      }, {
        value: 1,
        label: '参与官方活动'
      }, {
        value: 2,
        label: '官网.app顶专车或者个人消费后'
      }],
      pickerOptions: {
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            picker.$emit('pick', new Date());
          }
        }, {
          text: '昨天',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24);
            picker.$emit('pick', date);
          }
        }, {
          text: '一周前',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', date);
          }
        }]
      },
    }
  },
  //加载玩调用
  created() {
    this.initpointsTable();
  },

  methods:{
    handleClose(){
    },
    //1.初始化用户列表
    initpointsTable(){
      var that= this;
      this.$http.post(`/members/points/get/${this.currentPage}/${this.pageSize}`,this.pointsSelect).then(function (r) {
        that.tableData=r.data.result.records;
        that.total=r.data.result.total;
      })
    },
    //当改变没有显示的条数时触发该方法
    handleSizeChange(y){
      this.pageSize=y;
      this.initpointsTable();
    },
    //切换页码时触发该方法
    handleCurrentChange(y){
      this.currentPage=y;
      this.initpointsTable();
    }
  }
}
</script>

<style scoped>

</style>
